package com.huatai.bi.dto.bigScreen;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @BelongsProject: itc-airport-cloud
 * @BelongsPackage: com.itc.bi.dto.bigScreen
 * @Author: hecaiy
 * @CreateTime: 2024-07-13  13:38
 * @Description: TODO
 * @Version: 1.0
 */
@Data
@ApiModel(value = "大屏X轴配置")
public class BigScreenXAxisDTO implements Serializable{

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(notes = "数据集字段")
    private String key;

    @ApiModelProperty(notes = "升序字段")
    private String up;

    @ApiModelProperty(notes = "降序字段")
    private String down;

    @ApiModelProperty(notes = "自定义排序")
    private List<String> customOrder;

    @ApiModelProperty(notes = "字段名称")
    private String label;

    public String orderBy(){
        if(CollectionUtils.isNotEmpty(customOrder)){
            Collections.reverse(customOrder);
            String customOrderStr = customOrder.stream().collect(Collectors.joining("','"));
            return "indexOf(['"+customOrderStr+"'],`"+key+"`) desc";
        } else if(ObjectUtil.isNotEmpty(up)){
            return "`"+up+"` asc";
        }else if(ObjectUtil.isNotEmpty(down)){
            return "`"+down+"` desc";
        }
		return "";
    }
}
